aenum = function(){}
//加载栏目属性
aenum.ready = function(){
	var html = Acan.html.tag('table',{'class':'-table'},
		Acan.html.tag('tr',{},
			Acan.html.tag('td',{},Acan.html.tag('input',{type:'button',onclick:"aenum.newadd()",value:'添加数据'}))
			+Acan.html.tag('td',{id:'enum_add_type'})
		)
	);
	html += Acan.html.tag('table',{id:'enum_add_con','class':'-table'});//栏目编辑
	jQuery("#enum_add").append(html);
}
aenum.newadd = function(){
	var html = '';
	jQuery("#enum_add_con").html("");
	html = Acan.html.tag('tr',{},
		//Acan.html.tag('input',{type:'hidden','class':'madd_type',value:obj.value})+
		Acan.html.tag('td',{},Acan.html.tag('input',{type:'text','class':'madd_key'},'KEY:'))
		+Acan.html.tag('td',{},Acan.html.tag('input',{type:'text','class':'madd_value'},'值:'))
	)
	+Acan.html.tag('tr',{},
		Acan.html.tag('td',{colspan:"10",align:'center'},
			Acan.html.tag('input',{type:'button','class':'madd_btn_add',onclick:'aenum.save()',value:'添加'})
		)
	);
	jQuery("#enum_add_con").append(html);
}
aenum.save = function(id){
	delete mdata[id];
	var key = jQuery('.madd_key').val();
	mdata[key] = jQuery('.madd_value').val();
	aenum.list_refesh();
}
aenum.del = function(id){
	delete mdata[id];
	aenum.list_refesh();
}
aenum.edit = function(id){
	aenum.newadd();
	jQuery('.madd_key').val(id);
	jQuery('.madd_value').val(mdata[id]);
	jQuery('.madd_btn_add').remove();
	if(jQuery('.madd_btn_up').val()){return;}
	var html = Acan.html.tag('tr',{},
		Acan.html.tag('td',{colspan:"10",align:'center'},
			Acan.html.tag('input',{type:'button','class':'madd_btn_up',onclick:'aenum.save(\''+id+'\')',value:'保存'})
		)
	);
	jQuery("#enum_add_con").append(html);
}
aenum.ajax_save = function(id){
	if(typeof(id) == 'undefined'){id = '';}
	var save = jQuery("#save_form").serialize();
	if(typeof(mdata) == 'object')
		save += "&save[data]="+Acan.base.obj_json(mdata);
	jQuery.ajax({
		type: "POST",
		url: Aurl.Amodr+"-save-"+id,
		data: save,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert(data,1000);
		}
	})
}
//加载栏目列表
aenum.list = function(){
	var html = '';
	if(typeof(mdata) == 'object'){
		html += Acan.html.tag('tr',{},Acan.html.tag('th',{colspan:'10',align:'center'},'枚举列表'));
		html += Acan.html.tag('tr',{},
			Acan.html.tag('th',{},'KEY')
			+Acan.html.tag('th',{},'值')
			+Acan.html.tag('th',{},'操作')
		);
		for(x in mdata){
			html += Acan.html.tag('tr',{},
				Acan.html.tag('td',{},x)
				+Acan.html.tag('td',{},mdata[x])
				+Acan.html.tag('td',{},
					Acan.html.tag('input',{type:'button',onclick:'aenum.edit(\''+x+'\')',value:'编辑'})
					+Acan.html.tag('input',{type:'button',onclick:'aenum.del(\''+x+'\')',value:'删除'})
				)//操作按钮
			);
		}
	}
	var id = jQuery('.model_form_id').val();
	if(id == ''){
		var btn_text = '添加';
	}else{
		var btn_text = '更新';
	}
	html += Acan.html.tag('tr',{},
		Acan.html.tag('td',{colspan:'10',align:'center'},
			Acan.html.tag('input',{type:'button',onclick:'aenum.ajax_save('+id+')',value:btn_text})
			+Acan.html.tag('input',{type:'button',onclick:'Acan.url.back()',value:'返回'})
		)//操作按钮
	)
	html = Acan.html.tag('table',{'class':'-table'},html);//操作按钮
	jQuery("#enum_list").append(html);
}
aenum.list_refesh = function(){
	if(Acan.get('#enum_add') == null){return;}
	jQuery('#enum_add').html("");
	jQuery('#enum_list').html("");
	aenum.ready();
	aenum.list();
}
jQuery(document).ready(function(){
	aenum.list_refesh();
});